//
//  UILabel+Expand.m
//  App
//
//  Created by tenltrs on 2018/6/26.
//  Copyright © 2018年 Tenltrs. All rights reserved.
//

#import "UILabel+Expand.h"

@implementation UILabel (Expand)

-(void)ts_setRichTextFont:(UIFont*)font color:(UIColor *)textColor atRange:(NSRange)range NS_AVAILABLE_IOS(6_0){
    NSMutableAttributedString *str=(NSMutableAttributedString*)self.attributedText;
    if(font){
        [str addAttributes:@{NSFontAttributeName:font} range:range];
    }
    if(textColor){
        [str addAttributes:@{NSForegroundColorAttributeName:textColor} range:range];
    }
    self.attributedText=str;
}
-(void)ts_addLineAtRange:(NSRange)range NS_AVAILABLE_IOS(6_0){
    NSMutableAttributedString *str=(NSMutableAttributedString*)self.attributedText;
    [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:range];
    self.attributedText=str;
}


-(void)ts_attributedBeforeText:(NSString *)before AfterText:(NSString *)after AttributedText:(NSString *)attributed Parameter:(NSDictionary *)parameter{
    
    NSString * str=[NSString stringWithFormat:@"%@%@%@",before,attributed,after];
    NSRange range=[str rangeOfString:attributed];
    NSMutableAttributedString * att=[[NSMutableAttributedString alloc]initWithString:str];
    [att addAttributes:parameter range:range];
    self.attributedText=att;
}

@end
